<template>
  <div>
    <!-- 面包屑 -->
    <app-title :mytitle="mytitle"></app-title>

    <!-- 查询表单 -->
    <el-form :inline="true" :model="searchForm" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="searchForm.name" placeholder="姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="searchForm.sex"
          placeholder="性别"
          style="width:100px"
        >
          <el-option label="女" value="女"></el-option>
          <el-option label="男" value="男"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" icon="el-icon-search"
          >查询</el-button
        >
        <el-button type="success" icon="el-icon-plus">新增</el-button>
        <el-button type="warning" icon="el-icon-refresh">重置按钮</el-button>
      </el-form-item>
    </el-form>

    <!-- 用户列表 -->
    <el-table stripe :data="tableData" border style="width: 100%">
      <el-table-column type="index" prop="id" label="id" width="50">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="100"> </el-table-column>
      <el-table-column prop="sex" label="性别" width="50"> </el-table-column>
      <el-table-column prop="birthday" label="出生日期" width="100">
      </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
      <el-table-column prop="phone" label="手机号码" width="120">
      </el-table-column>
      <el-table-column prop="pic" label="头像"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary">编辑</el-button>
          <el-button type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页效果 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
    >
    </el-pagination>

    <!-- 弹框(模态框)-->
    <el-dialog title="新增用户" :visible.sync="dialogFormVisible" width="40%">
      <el-form :model="userform">
        <el-form-item label="姓名" :label-width="formLabelWidth">
          <el-input
            v-model="userform.name"
            autocomplete="off"
            style="width:200px"
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="性别" :label-width="formLabelWidth">
          <el-select
            v-model="userform.sex"
            placeholder="请选择性别"
            style="width:120px"
          >
            <el-option label="女" value="女"></el-option>
            <el-option label="男" value="男"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" :label-width="formLabelWidth">
          <el-date-picker
            v-model="userform.birthday"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="手机号" :label-width="formLabelWidth">
          <el-input
            v-model="userform.phone"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item>
        <el-form-item label="地址" :label-width="formLabelWidth">
          <el-input type="textarea" v-model="userform.address"></el-input>
        </el-form-item>
        <el-form-item label="头像" :label-width="formLabelWidth">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import appTitle from "../title";
export default {
  data() {
    return {
      dialogFormVisible: false, //新增用户的弹窗：默认是关闭的
      userform: {
        name: "",
        region: "",
      },
      formLabelWidth: "80px",
      fileList: [
        {
          name: "food.jpeg",
          url:
            "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
        {
          name: "food2.jpeg",
          url:
            "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
      ],
      mytitle: "用户管理",
      searchForm: {
        name: "",
        sex: "",
      },
      tableData: [
        {
          _id: "5f1dcb1f3f1eb819289bb8c7",
          username: "Rodriguez",
          name: "姜军",
          birthday: "1985-02-10",
          sex: "女",
          phone: "18683965065",
          address: "新疆维吾尔自治区 克拉玛依市 白碱滩区",
          pic: "http://dummyimage.com/50x50",
        },
        {
          _id: "5f1dcb1f3f1eb819289bb8c9",
          username: "Martin",
          name: "熊磊",
          birthday: "1972-03-10",
          sex: "女",
          phone: "15765182305",
          address: "陕西省 铜川市 耀州区",
          pic: "http://dummyimage.com/50x50",
        },
        {
          _id: "5f1dcb1f3f1eb819289bb8ca",
          username: "Davis",
          name: "武芳",
          birthday: "1984-06-23",
          sex: "男",
          phone: "15457397717",
          address: "吉林省 四平市 其它区",
          pic: "http://dummyimage.com/50x50",
        },
        {
          _id: "5f1dcb1f3f1eb819289bb8cd",
          username: "Perez",
          name: "白芳",
          birthday: "2005-11-19",
          sex: "男",
          phone: "15235178524",
          address: "广西壮族自治区 河池市 南丹县",
          pic: "http://dummyimage.com/50x50",
        },
        {
          _id: "5f1dcb1f3f1eb819289bb8ce",
          username: "Robinson",
          name: "唐杰",
          birthday: "2014-05-18",
          sex: "男",
          phone: "15456565514",
          address: "四川省 达州市 通川区",
          pic: "http://dummyimage.com/50x50",
        },
      ],
      currentPage4: 1,
    };
  },

  components: {
    //注册组件
    appTitle,
  },

  methods: {
    onSubmit() {
      console.log("submit!");
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>

<style scoped></style>
